package hotel.menu.adapter;

import hotel.menu.domain.Food;
import hotel.menu.untils.AsyncImageLoad;
import hotel.menu.untils.ConstantID;
import java.util.ArrayList;
import java.util.List;
import com.example.youknow.R;
import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

@SuppressLint({ "NewApi", "ResourceAsColor" })
public class Item2DetailAdapter extends BaseAdapter {

	private LayoutInflater inflater;
	private List<Food> derails;
	int last_item;
	private List<Integer> integers = new ArrayList<Integer>();
	private List<Integer> already_item = new ArrayList<Integer>();
	private Context context;

	public Item2DetailAdapter(Context context, List<Food> derails) {
		this.derails = derails;
		this.context = context;
		inflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		return derails.size();
	}

	@Override
	public Object getItem(int position) {
		return position;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.item2_content_detail_item,
					null);
			holder = new ViewHolder();
			holder.name = (TextView) convertView
					.findViewById(R.id.itme2_content_detail_name);
			holder.price = (TextView) convertView
					.findViewById(R.id.itme2_content_detail_price);
			holder.image = (ImageView) convertView
					.findViewById(R.id.itme2_content_detail_image);
			holder.hasnew = (ImageView) convertView
					.findViewById(R.id.itme2_content_detail_hasnew);
			holder.view2 = convertView
					.findViewById(R.id.itme2_content_detail_view2);
			holder.view1 = convertView
					.findViewById(R.id.itme2_content_detail_view1);
			holder.ly = (LinearLayout) convertView
					.findViewById(R.id.itme2_content_detail_ly);
			holder.fy = (FrameLayout) convertView
					.findViewById(R.id.itme2_content_detail_already_fy);
			holder.already_image1 = (ImageView) convertView
					.findViewById(R.id.itme2_content_detail_already_image1);
			holder.already_image2 = (ImageView) convertView
					.findViewById(R.id.itme2_content_detail_already_image2);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		Food detail = derails.get(position);
		holder.name.setText(detail.getDishname());
		holder.price.setText(detail.getPrice() + "");
		new AsyncImageLoad(context, holder.image, ConstantID.IMAGE_PATH
				+ detail.getPhoto());
		holder.ly.setBackgroundResource(R.color.details);
		holder.fy.setVisibility(8);
		holder.view2.setVisibility(8);
		holder.view1.setVisibility(0);
		holder.hasnew.setVisibility(8);
		if (integers.contains(position)) {
			holder.view2.setVisibility(0);
			holder.view1.setVisibility(8);
		}
		if (already_item.contains(detail.getDishid())) {
			holder.ly.setBackgroundResource(R.color.details_press);
			holder.fy.setVisibility(0);

		}
		if (detail.isHasnew()) {
			holder.hasnew.setVisibility(0);
		}

		return convertView;
	}

	public static class ViewHolder {
		public TextView name, price;
		public ImageView image, hasnew, hashot;
		public View view1, view2;
		public LinearLayout ly;
		public FrameLayout fy;
		public ImageView already_image1;
		public ImageView already_image2;
	}

	public void setView(List<Integer> list) {
		integers.clear();
		integers = list;
	}

	public void setAlreadyItem(int id) {
		if (already_item.contains(id)) {
			already_item.remove((Object) id);
		} else {
			already_item.add(id);
		}

	}

}
